﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UISystemConfig : MonoBehaviour
{
    // Start is called before the first frame update

    public Toggle toggleFirst;
    public Toggle toggleSecond;
    public InputField hostField;

    private void Start()
    {
        SystemConfig systemConfig = SystemConfigManager.GetSystemConfig();
        if(systemConfig != null)
        {
            if(systemConfig.ServerType == 1)
            {
                toggleFirst.isOn = true;
            } else if(systemConfig.ServerType == 2)
            {
                toggleSecond.isOn = true;
            }
            if(systemConfig.ServerHost != null)
            {
                hostField.text = systemConfig.ServerHost;
            }
        }
    }

    public void SaveSystemConfig()
    {
        bool isFirst = toggleFirst.isOn;
        bool isSecond = toggleSecond.isOn;
        string serverHost = hostField.text;
        SystemConfig systemConfig = new SystemConfig();
        int type = 0;
        if (isFirst)
        {
            type = 1;
        } else if (isSecond)
        {
            type = 2;
        }
        systemConfig.ServerType = type;
        systemConfig.ServerHost = serverHost;
        SystemConfigManager.UpdateSystemConfig(systemConfig);
        Debug.Log("save system config:" + type + "," + serverHost);
    }
}
